<template>
	<view>
		<u-navbar class="head" leftIcon="" :fixed="false" :safeAreaInsetTop="true"
			style="z-index: 99999999;position: relative;">
			<view class="u-nav-slot" slot="right">
				<m-capsule :closeHandler="CloseShopPage"></m-capsule>
			</view>
		</u-navbar>

		<web-view v-if="ShowWebView" ref="webview" fullscreen="false" @message="message" class="uni-flex-item"
			:src="OrderUrl">
		</web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ShowWebView: true,
				currentWebview: {},
				OrderUrl: '', // web-view地址
			};
		},
		onLoad(option) {
			var that = this;

			console.log(option.url)
			that.OrderUrl = '/hubird/html/qms/ShopPage/html/' + option.url + '.html';
			setTimeout(() => {


				that.currentWebview = that.$scope.$getAppWebview().children()[0];

				if (option.orderIndex && option.orderIndex >= 0) {
					that.currentWebview.evalJS(`vm.GetOrderIndex('${option.orderIndex}')`);
				}

				if (option.url == 'setMeal') {
					that.currentWebview.evalJS(`vm.GetActiveKey('${option.tabKey}')`);
				} else if (option.url == 'productList') {
					that.currentWebview.evalJS(`vm.GetSearchKey('${JSON.stringify(option)}')`);
				} else if (option.url == 'channel') {
					// var channelData = JSON.parse(decodeURIComponent(option.detailTypeList));
					let newOption = {
						data: JSON.parse(decodeURIComponent(option.detailTypeList))
					}

					that.currentWebview.evalJS(`vm.GetDetailTypeList('${JSON.stringify(newOption)}')`);
				}

				// that.$scope.$getAppWebview().children()[0].evalJS(`vm.GetVersion('${plus.runtime.version}')`);

			}, 300)
		},
		onReady() {
			var that = this;

			let height = 0; //定义动态的高度变量 
			let navbarHeight = 0;
			let tabbarHeight = 0
			uni.getSystemInfo({ // 获取当前设备的具体信息
				success: (sysinfo) => {
					// 总盒子高度
					height = sysinfo.windowHeight;
					// 导航栏高度
					uni.createSelectorQuery().select('.head').boundingClientRect(data => {
						navbarHeight = data.height
						height = height - data.height
						let currentWebview = this.$scope.$getAppWebview().children()[0]; //获取当前web-view
						var wv = currentWebview;
						wv.setStyle({ //设置web-view距离顶部的距离以及自己的高度，单位为px
							top: navbarHeight, //此处是距离顶部的高度，应该是你页面的头部
							height: height, //webview的高度
						})

					}).exec()

				}
			});

		},
		methods: {
			message(event) {
				var that = this
				// console.log('接收到消息', event.detail.data);

				if (event.detail.data[0]['action'] == 'GoBack') {
					uni.navigateBack()
				}

			},
			CloseShopPage() { // 关闭商城
				var that = this;
				// console.log(this.OrderUrl)
				that.ShowWebView = false;
				setTimeout(() => {

					uni.navigateBack({
						delta: 999
					})
				}, 50)
			},
		}
	}
</script>

<style>
</style>